package Demo;

public class Demo3 {
    //线程计算1+2+。。。。+100，在主线程打印结果
    public static int ret=0;

    public static void main(String[] args) {
        Thread mainThread=Thread.currentThread();
        Thread t=new Thread(()->{
            try {
                mainThread.join();
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
            System.out.println(ret);
        });
        t.start();
        for(int i=1;i<=100;i++) {
            ret += i;
        }
    }
    public static void main1(String[] args) throws InterruptedException {
        Thread t=new Thread(()->{
            for(int i=1;i<=100;i++){
                ret+=i;
            }
        });
        t.start();
        Thread.sleep(10000);
        System.out.println(ret);
    }
}
